package com.ITArmy.controller;

import com.ITArmy.beans.Reply;
import com.ITArmy.beans.Shows.ReplyMessage;
import com.ITArmy.common.ServerResponse;
import com.ITArmy.controller.base.BaseController;
import com.ITArmy.service.ReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("/reply")
@Api(value = "ReplyController", tags = "回复评论的接口")
@Controller
public class ReplyController extends BaseController {

    @RequestMapping("/replyComment")
    @ResponseBody
    @ApiOperation(value = "回复具体的评论", httpMethod = "POST")
    public ServerResponse replyComment(Reply reply) {
        return replyService.replyComment(request, reply);
    }

    @RequestMapping("/deleteReply")
    @ResponseBody
    @ApiOperation(value = "删除回复的评论", httpMethod = "DELETE")
    public ServerResponse deleteReply(long replyId) {
        return replyService.deleteReply(replyId);
    }

    @RequestMapping("/getReply")
    @ResponseBody
    @ApiOperation(value = "获取一个评论的所有回复信息", httpMethod = "GET")
    public PageInfo getReply(long cId,int page) {
        PageHelper.startPage(page, 6);
        List<ReplyMessage> replies = replyService.getReplyMessageByCid(cId);
        PageInfo blogPageInfo = new PageInfo<>(replies, 6);
        return blogPageInfo;
    }
}
